﻿using System;
using System.Data;
using System.Text;
using ZHDJ.Data.Models.Center;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.VolunteerActivitie
{
    public partial class VolunteerActiviteMore : UseMorePageMasterPage
    {
        public string BranchID
        {
            get
            {
                return this.Request["BranchID"] ?? "";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            StringBuilder sbHtml = new StringBuilder();
            sbHtml.Length = 0;
            int startIndex = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize;
            DataTable dt = null;
            DataTable dtCount = new DataTable();
            dtCount = null;
            int sumCount = 0;

            if (this.Category == "Call")
            {
                dtCount = PartyVolunteerActivitie.GetMoreActivitieTitle(-1, -1, BranchID).Tables[0];
                if (dtCount != null)
                {
                    sumCount = dtCount.Rows.Count;
                }
                AspNetPager1.RecordCount = sumCount;

                dt = PartyVolunteerActivitie.GetMoreActivitieTitle(AspNetPager1.PageSize, startIndex, BranchID).Tables[0];
                foreach (DataRow item in dt.Rows)
                {
                    sbHtml.Append("<li>");
                    sbHtml.Append("<span>" + Convert.ToDateTime(item["CreateTime"]).ToString("yyyy-MM-dd") + "</span>");
                    sbHtml.Append("<a href=\"VolunteerActiviteDetail.aspx?ID=" + Convert.ToString(item["ID"]) + "\" title=\"" + Convert.ToString(item["Title"]) + "\" >[" + Convert.ToString(item["IsEndName"]) + "]" + CutLongTitle(Convert.ToString(item["Title"]), 42) + "</a>");
                    sbHtml.Append("</li>");
                }
            }
            else
            {
                dtCount = PartyVolunteerQuotation.GetMoreQuotationTitle(-1, -1, BranchID).Tables[0];
                if (dtCount != null)
                {
                    sumCount = dtCount.Rows.Count;
                }
                AspNetPager1.RecordCount = sumCount;

                dt = PartyVolunteerQuotation.GetMoreQuotationTitle(AspNetPager1.PageSize, startIndex, BranchID).Tables[0];
                foreach (DataRow item in dt.Rows)
                {
                    sbHtml.Append("<li>");
                    sbHtml.Append("<span>" + Convert.ToDateTime(item["CreateTime"]).ToString("yyyy-MM-dd") + "</span>");
                    sbHtml.Append("<a href=\"VolunteerQuotationDetail.aspx?ID=" + Convert.ToString(item["ID"]) + "\" title=\"" + item["Content"] + "\" >" + CutLongTitle(Convert.ToString(item["Content"]), 42) + "</a>");
                    sbHtml.Append("</li>");
                }
            }

            liData.Text = sbHtml.ToString();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        /// <summary>
        /// 截取标题
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string CutLongTitle(object obj, int length)
        {
            string title = Convert.ToString(obj);
            if (title.Length > length)
            {
                title = title.Substring(0, length) + "...";
            }
            return title;
        }
    }
}